if (!isServer) exitwith {};

private ["_mpPosition", "_createMPcount", "_newPosition", "_mapsize", "_mpc"];

_mpPosition = [];
_createMPcount = 0;
_mapsize = (getPos NorthEast) distance (getPos SouthWest);

if (_mapsize < 5000) then {
	_mpc = 0;
}else{
	if (_mapsize < 10000) then {
		_mpc = 1;
	}else{
		if (_mapsize < 15000) then {
			_mpc = 2;
		}else{
			if (_mapsize < 20000) then {
				_mpc = 3;
			}else{
				if (_mapsize < 25000) then {
					_mpc = 4;
				}else{
					_mpc = 5;
				};
			};
		};
	};
};

if (isNil "A3E_MotorPoolCount") then {A3E_MotorPoolCount = (floor random _mpc)+Param_EnemyFrequency};

while {_createMPcount < A3E_MotorPoolCount} do {
    _createMPcount = _createMPcount + 1;
    _newPosition = [50, 1000, .1] call A3E_fnc_findFlatArea;
	//Check if too close to another depot, comcenter or start
	_tooCloseAnotherPos = false;
	{
        if (_newPosition distance _x < A3E_ClearedPositionDistance) exitwith {_tooCloseAnotherPos = true};
    } forEach A3E_Var_ClearedPositions;
    if (!_tooCloseAnotherPos) then {
        _mpPosition pushBack _newPosition;
		A3E_Var_ClearedPositions pushBack _newPosition;
    };
};

_playergroup = [] call A3E_fnc_getPlayerGroup;
_arr = [A3E_fnc_BuildMotorPool,A3E_fnc_BuildMotorPool2,A3E_fnc_BuildMotorPool3,A3E_fnc_BuildMotorPool4];
if (productVersion select 2 >= 200) then {
	_arr pushback A3E_fnc_BuildMotorPool5;
	_arr pushback A3E_fnc_BuildMotorPool6;
};
{
	[_x,50] call a3e_fnc_cleanupTerrain; //*清除半径内场地
	// Fixme: hard coding to 180° orientation for now
	[_x, 180, a3e_arr_ComCenStaticWeapons,
	a3e_arr_Escape_MilitaryTraffic_CivilianVehicleClasses, 
	a3e_arr_ComCenDefence_lightArmorClasses + a3e_arr_ComCenDefence_heavyArmorClasses]
	call (selectRandom _arr); //

    [_playergroup, "A3E_MotorPoolPatrolMarker", A3E_VAR_Side_Opfor, "INS", 5, 5, 8,
	Param_EnemySkill, Param_EnemySkill, Param_EnemySpawnDistance, false] spawn drn_fnc_InitGuardedLocations;
} forEach _mpPosition;

a3e_var_Escape_MotorPoolPositions = _mpPosition;
publicVariable "a3e_var_Escape_MotorPoolPositions";


